/**
 * @Author：ming
 * @Date：2023/10/2 9:39 PM
 * @Filename：Hj8
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;

/**
 * @author ming
 */
public class Hj8 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str ;
        while ((str=br.readLine())!=null){
            int n = Integer.valueOf(str);
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                String[] split = br.readLine().split(" ");
                int index = Integer.valueOf(split[0]);
                int value = Integer.valueOf(split[1]);
                if(map.containsKey(index)){
                    map.put(index,map.get(index)+value);
                }else {
                    map.put(index,value);
                }
            }
            ArrayList<Integer> list = new ArrayList<>(map.keySet());
            Collections.sort(list);

            for (Integer index : list) {
                System.out.println(index+" "+map.get(index));
            }
        }
    }
}
